﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.Practices.Unity;

namespace WDA.Core.DynamicReconfiguration
{	
	internal sealed class ReconfigurationProxy
	{
		private readonly ThreadStart _doReconfigurationCallback;

		[Dependency(WDAContainerNames.PersistentInternalContainerName)]
		public IUnityContainer Container { get; set; }

		public ReconfigurationProxy(ThreadStart doReconfigurationCallback)
		{
			_doReconfigurationCallback = doReconfigurationCallback;
		}

		public void ForceRemoteReconfiguration(long newVersion)
		{
			IUnityContainer transient = Container.Resolve<IUnityContainer>(WDAContainerNames.InternalContainerName);
			InterHostInterface ihi = transient.Resolve<InterHostInterface>();
			ihi.ForceRemoteReconfiguration(newVersion);
		}

		public void EnqueueReconfigurationTask()
		{
			DoReconfiguration();
		}

		private void DoReconfiguration()
		{
			_doReconfigurationCallback();
		}
	}
}
